-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix: prevent grey screen when VS Code LM API hits context window limits #8595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Added error recovery mechanism in vscode-lm.ts to detect and handle context window errors - Implemented client reset on context window errors to recover from stuck states - Enhanced handleContextWindowExceededError in Task.ts with try-catch and fallback truncation - Added non-blocking error handling to prevent UI freeze during context operations - Improved error handling in ClineProvider for context condensing operations - Made handleContextWindowExceededError public to allow recovery from ClineProvider Fixes #8594
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing my own code because apparently I trust myself more than I should.
| (lowerMessage.includes("maximum") && lowerMessage.includes("tokens")) || | ||
| lowerMessage.includes("too many tokens") || | ||
| lowerMessage.includes("exceeds") | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: The isContextWindowError() method uses simple string pattern matching which may not catch all VS Code LM API context window errors. Consider checking if the VS Code LM API provides specific error codes or types for context window errors that could be used for more reliable detection.
The current implementation relies on message text patterns which could produce false positives if error messages change or contain these keywords in different contexts.
| contextCondense, | ||
| ) | ||
| } | ||
| } catch (error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: The fallback truncation strategy keeps only the first message and last 2 messages. Consider if this is sufficient for maintaining conversation coherence. The first message might be the initial task description, but keeping only 2 recent messages might lose important context.
Suggestion: Document why this specific strategy (first + last 2) was chosen, or consider keeping a few more messages (e.g., first + last 5) to maintain better context.
This PR addresses Issue #8594 where the UI becomes unresponsive (grey screen) when using VS Code LM API during context window compaction.
Problem
Users experience a grey screen that prevents them from seeing task progress when the VS Code Language Model API hits context window limits. This forces users to restart VSCode and create new tasks to continue work, occurring 2-3 times daily.
Solution
Implemented comprehensive error recovery mechanisms:
1. VS Code LM API Handler (
src/api/providers/vscode-lm.ts)isContextWindowError()method to detect context window errors through pattern matchinghandleContextWindowError()recovery mechanism that resets the client stateisRecoveringflag to prevent recursive recovery attemptscreateMessage()andcompletePrompt()methods2. Task Context Management (
src/core/task/Task.ts)handleContextWindowExceededError()public for external recovery3. Webview Provider (
src/core/webview/ClineProvider.ts)condenseTaskContext()with recovery logic for context window errorscancelTask()error handling to prevent UI freezingTesting
Review Results
Code review confidence: 92% (High)
Fixes #8594
Important
Enhances error detection and recovery for context window limits in VS Code LM API to prevent UI unresponsiveness.
isContextWindowError()andhandleContextWindowError()invscode-lm.tsto detect and recover from context window errors.createMessage()andcompletePrompt()invscode-lm.tswith error handling for context window limits.handleContextWindowExceededError()public inTask.tsfor external recovery.Task.ts.Task.ts.condenseTaskContext()andcancelTask()inClineProvider.tswith recovery logic and user notifications.This description was created by
for 6deba15. You can customize this summary. It will automatically update as commits are pushed.